package com.gy.mbaselibrary.utils;

import android.os.Handler;
import android.os.Looper;

import com.gy.mbaselibrary.App;


/**
 * 创建者：高业
 * 邮箱：15234150168@163.com
 * 时间：2018/2/6
 * 描述：
 * 修改人：
 * 修改时间：2018/2/6
 * 修改备注：
 */
public class UIUtils {
    /**
     * 获取主线程的handler
     */
    public static Handler getHandler() {
        // 获得主线程的looper
        Looper mainLooper = App.getInstance().getMainThreadLooper();
        // 获取主线程的handler
        Handler handler = new Handler(mainLooper);
        return handler;
    }

    /**
     * 延时在主线程执行runnable
     */
    public static boolean postDelayed(Runnable runnable, long delayMillis) {
        return getHandler().postDelayed(runnable, delayMillis);
    }

    /**
     * 在主线程执行runnable
     */
    public static boolean post(Runnable runnable) {
        return getHandler().post(runnable);
    }

    public static boolean post(Runnable runnable, long delayMillis) {
        return postDelayed(runnable,delayMillis);
    }

    public static void startThread(Runnable runnable){
        new Thread(runnable).start();
    }

}
